package Seity;
import java.util.*;
import java.io.*;

/**
 * implements the data structure of one node in a hash table
 * @author zhangfan
 *
 */

public class SimpleNode {
	//A node contains an arrayList of tokens
	private ArrayList<SimpleToken> tokenNode = new ArrayList<SimpleToken>();
	
	/**
	 * get a specified token
	 * @param content
	 * @return a specified token of the arrayList
	 */
	public SimpleToken getToken(String content)
	{
		SimpleToken tempToken = null;
		for(int i = 0;i<tokenNode.size();i++)
		{
			tempToken = tokenNode.get(i);
			if(tempToken.getContent().equals(content))
			{
				return tempToken;
			}
		}
		return tempToken;
	}
	
	/**
	 * get the total list of tokens
	 * @return all tokens
	 */
	public ArrayList<SimpleToken> getAllToken()
	{
		return tokenNode;
	}
	
	/**
	 * get the size of the node
	 * @return the size of the node
	 */
	public int size()
	{
		return tokenNode.size();
	}
	
	/**
	 * add a specified token in the arrayList
	 * @param content
	 * @param index
	 * @return the index of the specified token
	 */
	public int addToken(String content,int index)
	{
		for(int i = 0;i<tokenNode.size();i++)
		{
			SimpleToken tempToken = tokenNode.get(i);
			if(tempToken.getContent().equals(content))
			{
				int count = tempToken.getCount() + 1;
				tempToken.setCount(count);    //if the token already exists,then add the count of the token
				return tempToken.getIndex();  //if the token already exists,then return the index of it
			}
		}
		int index2 = index + 1;               //if the token does not exist,then add a new token
		SimpleToken newToken = new SimpleToken(content,1,index2);
		tokenNode.add(newToken);
		return index2;
	}
	
	/**
	 * add a specified token in the arrayList
	 * @param token
	 */
	public void addToken(SimpleToken token)
	{
		tokenNode.add(token);
	}
}
